public class Solution {
    public int addDigits(int num) {
        if (num < 10) {
            return num;
        }
        int next = 0;
        while (num != 0) {
            next = next + num % 10;
            num /= 10;
        }
        return addDigits(next);
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int num = 38;
        System.out.println(solution.addDigits(num));
    }
}
